from data_access.dao.task_dao import TaskDAO
from service.base_service.database_service import DatabaseService
from service.base_service.service_service import ServiceService
from service.base_service.sql_service import SqlService
from service.base_service.table_service import TableService


class TaskService:
    def __init__(self):
        self.task_dao = TaskDAO()

    def get_task_by_task_id(self, dispatch_code, task_id):
        task = self.task_dao.get_task_by_task_id(dispatch_code, task_id)
        task.sql = SqlService().get_sql_by_sql_id(dispatch_code, task.sql_id)
        task.execute_database = DatabaseService().get_database_by_database_id(dispatch_code, task.execute_database_id)
        task.storage_database = DatabaseService().get_database_by_database_id(dispatch_code, task.storage_database_id)
        task.storage_table = TableService().get_table_by_table_id(dispatch_code, task.storage_table_id)
        task.receive_service = ServiceService().get_service_by_service_id(dispatch_code, task.receive_service_id)
        return task

    def get_all_tasks_auto(self):
        return [task.as_dict() for task in self.task_dao.get_all_tasks()]

    def update_task_by_id(self, id, **kwargs):
        return self.task_dao.update_task_by_id(id, **kwargs)
